 <?php
 session_start();
 include_once ("Login/databaseconnection.php");
 $current_table="deleted_lab";
 date_default_timezone_set("Europe/Paris");
  	$t_d=date("Y/m/d");
   $Lab_Id=$_GET['Lab_Id'];
   $School_Id=$_GET['School_Id'];
   $sqlre=mysql_query("SELECT * FROM deleted_lab WHERE Lab_Id='$Lab_Id' AND School_Id='$School_Id'");
	if(mysql_num_rows($sqlre)!=0)
	{
		$School_Id=$_POST['School_Id'];
		$Lab_Id=$_POST['Lab_Id'];
		$Source_Of_Power=$_POST['Source_Of_Power'];
		$Tp_Number=$_POST['Tp_Number'];
		$Account_Number=$_POST['Account_Number'];
		$Date_of_commencement=$_POST['Date_of_commencement'];
		$Last_Updated_Date=$_POST['Last_Updated_Date'];
		$Accessed_By=$_POST['Accessed_By'];		
		$_SESSION['Accessed_By']=$Accessed_By;
		$sql=mysql_query("INSERT INTO lab(Lab_Id,School_Id,Source_Of_Power,Tp_Number,Account_Number,Date_of_commencement,Last_Updated_Date) VALUES('$Lab_Id','$School_Id','$Source_Of_Power','$Tp_Number','$Account_Number','$Date_of_commencement','$t_d')");
if($sql)
{ 
if($row=mysql_fetch_array($sqlre))
	{
	$Res_Id=$row['Resource_Id'];
	$Ser_Number=$row['Serial_Number'];
	$Func=$row['Functioning'];
    $B_Name=$row['Brand_Name'];
    $Date_Of_Supp=$row['Date_Of_Supplied'];
    $Name_Of_Supp=$row['Name_Of_Supplier'];
    $Fun_Source=$row['Funding_Source'];
	
	$Resource_Id=explode(",",$Res_Id);
	$Serial_Number=explode(",",$Ser_Number);
	$Functioning=explode(",",$Func);
    $Brand_Name=explode(",",$B_Name);
    $Date_Of_Supplied=explode(",",$Date_Of_Supp);
    $Name_Of_Supplier=explode(",",$Name_Of_Supp);
    $Funding_Source=explode(",",$Fun_Source);
	for($i=0;$i<count($Resource_Id);$i++)
	{
	mysql_query("INSERT INTO resource_details(Resource_Id,Lab_Id,Serial_Number,Functioning,Brand_Name,Date_Of_Supplied,Name_Of_Supplier,Funding_Source,School_Id,Last_Updated_Date)values('$Resource_Id[$i]','$Lab_Id','$Serial_Number[$i]','$Functioning[$i]','$Brand_Name[$i]','$Date_Of_Supplied[$i]','$Name_Of_Supplier[$i]','$Funding_Source[$i]','$School_Id','$t_d')");
	}
			
	$Availability_Of_LAN=$row['Availability_Of_LAN'];
   $LAN_Supplier=$row['LAN_Supplier'];
    $Supplied_Date=$row['Supplied_Date'];
   $Speed_Of_WAN=$row['Speed_Of_WAN'];
   $Wired_Date=$row['Wired_Date'];
   $WAN_Connection_Type=$row['WAN_Connection_Type'];
	$Internet_Facilities=$row['Internet_Facilities'];
	mysql_query("INSERT INTO network(Lab_Id,School_Id,Availability_Of_LAN,LAN_Supplier,Speed_Of_WAN,Supplied_Date,WAN_Connection_Type,Wired_Date,Internet_Facilities,Last_Updated_Date)values('$Lab_Id','$School_Id','$Availability_Of_LAN','$LAN_Supplier','$Speed_Of_WAN','$Supplied_Date','$WAN_Connection_Type','$Wired_Date','$Internet_Facilities','$t_d')");
   }
	$resultdel=mysql_query("DELETE FROM deleted_lab WHERE Lab_Id='$Lab_Id' AND School_Id='$School_Id'");
if(!$resultdel)
{
	$_SESSION['error']="But this record is not removed from the recycle bin!";
}
$_SESSION['error']="Successfully restored!";
}
   if(!$sql)
{
	 $_SESSION['error']="Sorry,an error occured  please try again!";
}	
}
?>
